<style>
  /*#warehouseProductionLine-edit .layui-table-body {*/
  /*    margin-right: -17px;*/
  /*}*/
  .layui-layer-title {
    display: flex;
    align-items: center;
  }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label">生产车间</label>
                  <div class="layui-input-inline mr0">
                    <select id="workshop" name="workshopId" lay-filter="workshopId"></select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">产线编号</label>
                  <div class="layui-input-inline mr0">
                    <input name="productionLineCode" class="layui-input" type="text" placeholder="请输入产线编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
              <div class="query-rt"></div>
            </div>
          </div>
        </div>

        <div class="lay-btn-rows">
          <div class="lay-btn-box">
            <div class="lay-btn-lt">
              <button id="warehouseProductionLineBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
            </div>
            <div class="lay-btn-rt"></div>
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <table class="layui-table" id="warehouseProductionLine" lay-filter="warehouseProductionLine"></table>
    </div>
  </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="warehouseProductionLineBar">
  <a class="layui-btn layui-btn-xs layui-btn" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-xs layui-btn" lay-event="detail">详情</a>
</script>

<style>
  #warehouseProductionLine-form .layui-disabled {
    color: #393d49 !important;
  }
</style>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "util", "table", "admin", "laytpl", "laydate", "tableTreeDj"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var util = layui.util;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laytpl = layui.laytpl;
    var laydate = layui.laydate;
    var tableTree = layui.tableTreeDj;
    await admin.initDataSelectPro("enterprise/device/admin/deviceWorkshop/list", {}, "workshop", "生产车间", () => {});
    // 渲染表格
    var insTb = table.render({
      elem: "#warehouseProductionLine",
      url: config.base + "warehouse/warehouse/productionLine/list",
      toolbar: true,
      defaultToolbar: ["filter"],
      where: { access_token: config.getToken().access_token },
      page: true,
      cellMinWidth: 100,

      cols: [
        [
          { type: "numbers", title: "序号" },
          { field: "productionLineCode", align: "center", title: "产线编号" },
          { field: "productionLineName", align: "center", title: "产线名称" },
          { field: "workshopName", align: "center", title: "所属车间" },
          { field: "remark", align: "center", title: "描述" },
          { field: "status", align: "center", title: "状态", templet: function (d) {
            return d.status == 1 ? "启用" : "停用";
          } },
          { field: "createTime", align: "center", title: "创建时间" },
          { align: "center", toolbar: "#warehouseProductionLineBar", title: "操作" }
          //
        ]
      ]
    });

    // 工具条点击事件
    table.on("tool(warehouseProductionLine)", function (obj) {
      var data = obj.data;
      var layEvent = obj.event;
      if (layEvent === "detail") {
        openFormFun("detail", data);

        // admin.req(
        //   "warehouse/warehouse/warehouseProductionLine/selectProductionDetail",
        //   {
        //     id: data.id
        //   },
        //   (res) => {
        //     if (res.code === 200) {
        //       openFormFun("detail", res.data);
        //     }
        //   }
        // );
      } else if (layEvent === "edit") {
        openFormFun("edit", data);
      }
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
    });

    form.render("select");

    // 添加按钮点击事件
    $("#warehouseProductionLineBtnAdd").click(function () {
      openFormFun("add");
    });

    function openFormFun(eventName, data) {
      admin.formOpen({
        area: "600px",
        offset: "10%",
        title: "配置订单物料信息",
        path: "components/warehouse/product/warehouseProductionLineForm.html",
        success: function () {
          parentData.eventName = eventName;
          parentData.data = data;
        }
      });
    }
  });
</script>
